//
//  MPMoreController.m
//  MarkPlatform
//
//  Created by xiao6 on 2017/12/18.
//  Copyright © 2017年 AT. All rights reserved.
//

#import "MPMoreController.h"
#import "MPMenuModel.h"
#import "MPMoreController.h"
#import "MPPrivacyController.h"
#import "MPMoreInfoCell.h"

@interface MPMoreController ()

@property (nonatomic, strong) NSArray<MPMenuModel *> *dataList;

@end

@implementation MPMoreController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self showNavTitle:@"更多信息" backItem:YES];
    
    [self setupViews];
    
    @weakify(self)
#if defined(DEBUG)
    NSString *version = [NSString stringWithFormat:@"%@(D%@)", [UIApplication sharedApplication].appVersion,
                         [UIApplication sharedApplication].appBuildVersion];
#elif defined(ADHOC)
    NSString *version = [NSString stringWithFormat:@"%@(A%@)", [UIApplication sharedApplication].appVersion,
                         [UIApplication sharedApplication].appBuildVersion];
#else
    NSString *version = [UIApplication sharedApplication].appVersion;
#endif

    self.dataList = @[
                      [MPMenuModel modelWithTitle:@"隐私条款" detailText:nil didClick:^{
                          @strongify(self)
                          [self.navigationController pushViewController:[[MPPrivacyController alloc] init] animated:YES];
                      }],
                      [MPMenuModel modelWithTitle:@"版本信息" detailText:version didClick:nil],
#if defined(DEBUG) || defined(ADHOC)
                      [MPMenuModel modelWithTitle:@"运行环境" detailText:[ATOnline isOnline] ? @"正式环境" : @"测试环境" didClick:^{
                          [ATAlertView showTitle:@"切换运行环境"
                                         message:[NSString stringWithFormat:@"确定要切换到%@环境?", ![ATOnline isOnline] ? @"正式" : @"测试"]
                                   normalButtons:@[@"取消"]
                                highlightButtons:@[@"切换"]
                                      completion:^(NSInteger index, NSString *buttonTitle) {
                                          if (index == 1) {
                                              [ATOnline switchEnvironment:![ATOnline isOnline]];
                                          }
                                      }];
                      }],
#endif
                      ];
}

#pragma mark - delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataList.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [MPMoreInfoCell cellHeight];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MPMoreInfoCell *cell = [MPMoreInfoCell cellForTableView:tableView indexPath:indexPath];
    cell.model = self.dataList[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    MPMenuModel *model = self.dataList[indexPath.row];
    !model.didClickBlock ?: model.didClickBlock();
}

#pragma mark - setupViews
- (void)setupViews {
//    self.tableView.scrollEnabled = NO;
}


@end
